
package com.jf.cloud.supplier.listener;

import com.jf.cloud.api.multishop.bo.OrderChangeShopWalletAmountBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import com.jf.cloud.common.util.Json;
import com.jf.cloud.supplier.service.SupplierWalletService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author zz
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.REFUND_SHOP_NOTIFY_SERVICE_TOPIC,consumerGroup = RocketMqConstant.REFUND_SHOP_NOTIFY_SUPPLIER_GROUP)
public class OrderRefundSupplierConsumer implements RocketMQListener<OrderChangeShopWalletAmountBO> {

    private static final Logger logger = LoggerFactory.getLogger(OrderRefundSupplierConsumer.class);

    @Autowired
    private SupplierWalletService supplierWalletService;

    /**
     * 订单退款 供应商减少余额
     */
    @Override
    public void onMessage(OrderChangeShopWalletAmountBO orderChangeShopWalletAmountBO) {
        if(Objects.isNull(orderChangeShopWalletAmountBO.getSupplierHandleStatus()) || Objects.equals(orderChangeShopWalletAmountBO.getSupplierHandleStatus(),-1)) {
            return;
        }
        logger.info("订单退款,供应商减少余额... message: " + Json.toJsonString(orderChangeShopWalletAmountBO));
        supplierWalletService.refundSupplierAmountByRefund(orderChangeShopWalletAmountBO);
    }
}
